from typing import *


class Solution:

    def permute(self, nums: List[int]) -> List[List[int]]:
        ans = []
        n = len(nums)

        def swap(id, i):
            nums[id], nums[i] = nums[i], nums[id]

        def f(id=0):
            if id == n - 1:
                ans.append(nums.copy())
                return
            for i in range(id, n):
                swap(id, i)
                f(id + 1)
                swap(id, i)

        f()
        return ans